***********************************************************************************************
***
***	INTERTEMPORAL EVIDENCE ON THE STRATEGY OF POPULISM IN THE US (Gennaro, Lecce, Morelli)
***	Replication Package
***  
*** Table 1
***
***********************************************************************************************



clear
est clear 

* Indicate location of the replication package here
cd "/Replication Package"

**********************************************
* Upload Data                            *****
**********************************************


use "3_data/for_analysis/congress_election_both.dta", clear

**********************************************
* Variables and sample                   *****
**********************************************

* Sample
keep if uncont==0 & indep==0

* Model
local outvar "pop_dim2_s"
local controls "female i.age_cat_num i.ethnicity2 i.educ_cat len_words i.election_year"

egen mediane = median(econ)
gen econh = econ>mediane
replace econh = . if econ == .
drop mediane 



**********************************************
* Results.                               *****
**********************************************

est clear

* Main
eststo: areg `outvar' i.outsider_correct `controls', a(state) cluster(district)
eststo: areg `outvar' i.outsider_correct##c.econ `controls' , a(state) cluster(district)
eststo: areg `outvar' i.outsider_correct##i.competitivedistricts##c.econ `controls' , a(state) cluster(district)

* Binary econ insecurity
eststo: areg `outvar' i.outsider_correct##i.competitivedistricts##i.econh `controls' , a(state) cluster(district)

* Split by insider vs outsider
eststo: areg `outvar' i.competitivedistricts##c.econ `controls' if outsider_correct==1, a(state) cluster(district)
eststo: areg `outvar' i.competitivedistricts##c.econ `controls' if outsider_correct==0, a(state) cluster(district)

* Robustness
eststo: areg `outvar' i.outsider_correct##i.competitivedistricts##c.econ `controls' if neo_insider==0, a(state) cluster(district)
eststo: areg `outvar' i.outsider_correct##i.competitivedistricts##c.econ `controls' if dist_outsider==1 & dist_insider==1, a(state) cluster(district)
eststo: areg `outvar' i.outsider_correct##i.competitivedistricts##c.econ `controls' , a(district) cluster(district)

* Save
esttab _all using "4_results/tables/tab1.tex", f label replace booktabs alignment(D{.}{.}{-1}) keep(1.outsider_correct 1.competitivedistricts econ 1.econh 1.outsider_correct#1.competitivedistricts 1.outsider_correct#c.econ 1.competitivedistricts#c.econ  1.outsider_correct#1.competitivedistricts#c.econ 1.outsider_correct#1.econh 1.competitivedistricts#1.econh  1.outsider_correct#1.competitivedistricts#1.econh) s(N r2, fmt(0 2) label("Observations" "R-squared")) nomtitles star(* 0.10 ** 0.05 *** 0.01) r2 b(3) se(3) brac nonotes 


*************************
*  Linear combination
*************************

local outvar "pop_dim2_s"
local controls "female i.age_cat_num i.ethnicity2 i.educ_cat len_words i.election_year"

qui areg `outvar' i.outsider_correct##i.competitivedistricts##c.econ `controls' , a(state) cluster(district)

* Outsider in non competitive areas
lincom econ + 1.outsider_correct#c.econ

* Outsider in competitive areas
lincom econ + 1.competitivedistricts#c.econ + 1.outsider_correct#c.econ + 1.outsider_correct#1.competitivedistricts#c.econ

